package com.txzt.gaea.config;

import com.txzt.gaea.common.constant.Constants;
import com.txzt.gaea.common.core.interceptor.AdminPermissionSeperateInterceptor;
import com.txzt.gaea.common.core.interceptor.ToolInvoker;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Created by P318 on 2019/5/5.
 */
@Configuration
public class AuthConfig implements WebMvcConfigurer {

    /**
     * 主系统权限拦截器
     * @return
     */
    @Bean
    public AdminPermissionSeperateInterceptor getAdminPermissionSeperateInterceptor() {
        return new AdminPermissionSeperateInterceptor(new ToolInvoker() {
            @Override
            public String toolCode() {
                return Constants.TOOL_CODE;
            }

            @Override
            public String toolVersion() {
                return Constants.TOOL_VERSION;
            }
        });
    }


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
//        这里有一个坑，静态资源放前面
        String[] exclude = new String[]{"/static/**",
                "/biz/token",
                "/gen/**",
                "/file/open/ofd",
//                "/plan/**",
//                "/dict/**",
//                "/dept/**"
        };
        //addPathPatterns("/**")表示拦截所有请求
        //excludePathPatterns("/login")表示排除的请求
        registry
                .addInterceptor(getAdminPermissionSeperateInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns(exclude);
    }
}
